package com.sky.mapper;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author hu
 * @date 2025/6/27
 */
@Mapper
public interface ShoppingCardMapper {

    /**
     * 查询要添加购物车的商品是否已经存在
     *
     * @return
     */
    List<ShoppingCart> list(ShoppingCart shoppingCart);

    /**
     * 根据ID修改商品数量
     *
     * @param cart
     */
    @Update("update shopping_cart set number = #{number} where id  = #{id}")
    void updateNumberById(ShoppingCart cart);

    /**
     * 添加到购物车
     * @param shoppingCart
     */
    @Insert("insert into shopping_cart (name, image, user_id, dish_id, setmeal_id, dish_flavor, amount, create_time) " +
            "values (#{name},#{image},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{amount},#{createTime});")
    void insert(ShoppingCart shoppingCart);

    /**
     * 清空购物车
     * @param shoppingCart
     */
    void deleteShopCard(ShoppingCart shoppingCart);
}
